package com.yzt.message.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.yzt.zhuju.arouter.RouterMain;
import com.yzt.zhuju.network.entity.message.CompanyNoticeData;
import com.yzt.p_base.utils.DateUtils;
import com.yzt.plugin_imageloader.ImageLoadUtil;
import com.yzt.plugin_widget.RoundImageView;
import com.yzt.message.R;

/**
 * author : bob
 * date   : 2022/12/5
 * desc   : 官方公告
 */
public class OfficeNoticeAdapter extends BaseQuickAdapter<CompanyNoticeData, BaseViewHolder> {

    public OfficeNoticeAdapter() {
        super(R.layout.item_office_notice);
    }

    @Override
    protected void convert(BaseViewHolder helper, CompanyNoticeData item) {

        helper.setText(R.id.tv_time, DateUtils.millis2String(item.getTime()));

        RoundImageView ivNoticeAdv = helper.getView(R.id.iv_notice_adv);
        if (!TextUtils.isEmpty(item.getImage())) {
            ivNoticeAdv.setVisibility(View.VISIBLE);
            ImageLoadUtil.loadIv(ivNoticeAdv.getContext(), item.getImage(), ivNoticeAdv);
        } else {
            ivNoticeAdv.setVisibility(View.GONE);
        }

        helper.setText(R.id.tv_title, item.getTitle());
        helper.setText(R.id.tv_content, item.getContent());

        LinearLayout llDetail = helper.getView(R.id.ll_detail);
        llDetail.setVisibility(TextUtils.isEmpty(item.getUrl()) ? View.GONE : View.VISIBLE);

        llDetail.setOnClickListener(v -> RouterMain.goToWeb(item.getUrl()));
    }
}
